package com.dubbo.demo.service;

import com.dubbo.demo.dto.UserAddDTO;
import com.dubbo.demo.dto.UserDTO;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@org.apache.dubbo.config.annotation.Service(protocol = "dubbo", version = "1.0.0", group = "")
public class ProviderUserServiceImpl implements UserService {


    @Reference(version = "1.0.0", group = "sharding")
    private ShardingService shardingService;

    Logger logger = LoggerFactory.getLogger(ProviderUserServiceImpl.class);


    @Override
    public UserDTO get(Long id) {



        UserDTO d = new UserDTO();
                d.setId(id);
                d.setName(shardingService.test() + id);
                d.setGender((int) (id % 2 + 1)); // 1 - 男；2 - 女
        return d;
    }

    @Override
    public Integer add(UserAddDTO addDTO) {
        return (int) (System.currentTimeMillis() / 1000); // 嘿嘿，随便返回一个 id
    }

}